<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Jedrzej\Pimpable\PimpableTrait;

class SmsRecord extends Model
{
    use HasFactory;
    use PimpableTrait;
    use SoftDeletes;

    /**
     * 可批量赋值的字段
     */
    public $fillable = [
        'platform_account',
        'user_id',
        'phone',
        'content',
        'template_id',
        'add_ip',
        'resultcode',
    ];

    /**
     * 返回状态码的类型
     */
    public $resultCodeEnum = [
        100 => '成功',
        130 => '失败',
        131 => '空号',
        132 => '停机',
        133 => '关机',
        134 => '无状态',
    ];

    /**
     * 可执行搜索的字段
     */
    public $searchable = [
        'id',
        'user_id',
        'phone'
    ];

    /**
     * 默认使用倒叙的字段
     */
    public $defaultSortCriteria = [
        'id,desc',
    ];

    /**
     * 短信发送记录关联的用户表
     */
    protected function user()
    {
        return $this->belongsTo(User::class,'user_id','id');
    }

    /**
     * 短信记录表关联的消息模板的id
     */
    protected function templateMessages()
    {
        return $this->belongsTo(TemplateMessage::class,'template_id','id');
    }
}
